<?php
session_start();
require_once( 'configs/config.php' );
require_once( 'lib/db.php' );

if( $_SERVER['REQUEST_METHOD'] == 'GET' )
{
	echo 'No post.';
	exit;
}

$formFields = array( 'Amount', 'Reason');

foreach( $formFields as $field )
{
	$form[ $field ] = htmlentities( trim( $_POST[ $field ] ), ENT_QUOTES );
	$form[ $field ] = $db->escape( $form[ $field ] );
}

$users = $_POST['users'];
sort($users);


// Insert into the database

$query = 'INSERT INTO payments (UserUID, Amount, Reason, Date) VALUES';
foreach($users as $key => $value)
{
	$query .= '(\'' .  $value . '\', \'' . $form['Amount'] . '\', \'' . $form['Reason'] . '\', CURDATE()),';
}


$query =  substr($query, 0, -1) . ';';

if( $db->query( $query ) )
{
	$submit = 'Submitted.';
	include_once('addPayment.php');
}
else
{
	echo 'Error';
}
?>